
from fastapi import FastAPI, Depends
from typing import Callable
from utils.mysql import create_tables

def startup(app: FastAPI) -> Callable:
    """
    FastApi 启动完成事件
    """

    async def app_start() -> None:
        # APP启动完成后触发
        print("-------------  fastapi已启动  -------------")
        
        create_tables()

    return app_start


def stopping(app: FastAPI) -> Callable:
    """
    FastApi 停止事件
    """

    async def stop_app() -> None:
        # APP停止时触发
        print("-------------  fastapi已停止  -------------")

    return stop_app


def register_events(app: FastAPI):
    """
    注册中间件
    """
    app.add_event_handler("startup", startup(app))
    app.add_event_handler("shutdown", stopping(app))